/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bean.chart;

import com.bean.chart.editors.ColorPanel;
import com.bean.chart.iterfaces.AbstractChartLegend;
import com.bean.chart.iterfaces.DataObserver;
import com.bean.chart.iterfaces.LegendDataProvider;
import java.awt.Color;
import java.awt.Dimension;
import java.beans.*;
import java.io.Serializable;
import java.util.ArrayList;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author sammael
 */
public class ChartLegend extends JPanel implements AbstractChartLegend, DataObserver, Serializable {
    
    public final static String PROP_LABEL = "label";
    public final static String PROP_BACKGROUND = "back";
    public final static String PROP_FOREGROUND = "fore";
    public final static String PROP_LABEL_VISIBLE = "labelVisible";
    public final static String PROP_SAMPLE_VISIBLE = "sampleVisible";
    public final static String PROP_ROWCOUNT = "rowcount";
    public final static String PROP_COLUMNCOUNT = "coulmncount";
    public final static String PROP_SAMPLE_SIZE = "samplesize";
    
    //Properties
    private PropertyChangeSupport propertySupport;
    private String label;
    private Color legendBackground;
    private Color legendForeground;
    private boolean legendLabelVisible;
    private boolean colorSampleVisible;
    private int rowCount;
    private int columnCount;
    private Dimension sampleSize;
    private LegendDataProvider provider;
    
    //Components
    private JLabel labelLbl;
    private ArrayList<JLabel> chartName;
    private ArrayList<ColorPanel> chartColor;
    
    public ChartLegend() {
        propertySupport = new PropertyChangeSupport(this);
    }

    @Override
    public void setLegendLabel(String label) {
        String old = this.label;
        this.label = label;
        labelLbl.setText(label);
        propertySupport.firePropertyChange(PROP_LABEL, old, label);
    }

    @Override
    public String getLegendLabel() {
        return label;
    }

    @Override
    public void setLegendBackground(Color color) {
        Color old = this.legendBackground;
        this.legendBackground = color;
        propertySupport.firePropertyChange(PROP_BACKGROUND, old, color);
    }

    @Override
    public Color getLegendBackground() {
        return legendBackground;
    }

    @Override
    public void setLegendForeground(Color color) {
        Color old = this.legendForeground;
        this.legendForeground = color;
        propertySupport.firePropertyChange(PROP_FOREGROUND, old, color);
        
    }

    @Override
    public Color getLegendForeground() {
        return legendForeground;
    }

    @Override
    public void setLegendLabelVisible(boolean visible) {
        boolean old = this.legendLabelVisible;
        this.legendLabelVisible = visible;
        propertySupport.firePropertyChange(PROP_LABEL_VISIBLE, old, visible);
    }

    @Override
    public boolean isLegendLabelVisible() {
        return this.legendLabelVisible;
    }

    @Override
    public void setColorSampleVisible(boolean visible) {
        boolean old = this.colorSampleVisible;
        colorSampleVisible = visible;
        propertySupport.firePropertyChange(PROP_SAMPLE_VISIBLE, old, visible);
        
    }

    @Override
    public boolean isColorSampleVisible() {
        return colorSampleVisible;
    }

    @Override
    public void setRowCount(int count) {
        int old = rowCount;
        rowCount = count;
        propertySupport.firePropertyChange(PROP_ROWCOUNT, old, count);
    }

    @Override
    public int getRowCount() {
        return rowCount;
    }

    @Override
    public void setColumnCount(int count) {
        int old = columnCount;
        columnCount = count;
        propertySupport.firePropertyChange(PROP_COLUMNCOUNT, old, count);
    }

    @Override
    public int getColumnCount() {
        return columnCount;
    }

    @Override
    public void setColorSampleSize(Dimension d) {
        Dimension old = sampleSize;
        sampleSize = d;
        for(ColorPanel cp : chartColor)
            cp.setPreferredSize(sampleSize);
        propertySupport.firePropertyChange(PROP_SAMPLE_SIZE, old, d);
    }

    @Override
    public Dimension getColorSampleSize() {
        return sampleSize;
    }

    @Override
    public void setDataProvider(LegendDataProvider provider) {
        this.provider = provider;
    }

    @Override
    public LegendDataProvider getDataProvider() {
        return provider;
    }
    
    private void redistribution(){
        
    }

    @Override
    public void update() {
        redistribution();
    }
    
    
}
